from sqlalchemy.orm import sessionmaker
from orm01 import engine, Student
import uuid
Session = sessionmaker(bind=engine)  # 获取session工厂类
session = Session()  # 创建一个session实例
print(session)
# session2 = Session()  # 此时创建的是两个session对象
obj = Student(id=str(uuid.uuid1()).replace("-", ""), name="姚振", age=25)
session.add(obj)

obj2 = Student(name="姚振", age=25)
session.add(obj2)

# session.add_all([  # 批量添加
#     Student(id=str(uuid.uuid1()).replace("-", ""), name="何毅", age=24),
#     Student(id=str(uuid.uuid1()).replace("-", ""), name="崔杰", age=26),
# ])
session.commit()